#ifdef HAVE_CONFIG_H
#        include <config.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "support.h"
#include "newinfo.h"
#include "clist.h"
#include "file.h"
#include "newwindow.h"
#include "update.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
        g_object_set_data_full (G_OBJECT (component), name, \
                gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
        g_object_set_data (G_OBJECT (component), name, widget)
        
GtkWidget* 
create_window_update_info (struct newinfo_struct *newinfo,struct clist_struct *clist)
{
	GtkWidget *window;
	GtkWidget *clist_show=clist->clist_show;
	gchar *info[MAX_COLUMNS];
	gint i;
	window=create_new_info_window(newinfo,clist);
	gtk_window_set_title (GTK_WINDOW (window), _(
	"\344\277\256\346\224\271\344\277\241\346\201\257"));
	gtk_window_set_icon_name (GTK_WINDOW (window), "gtk-refresh");
	
	for(i=0;i<newinfo->global_file->cur_file->col_nums;i++) {
		gtk_clist_get_text(GTK_CLIST(clist_show),clist->show_selected_row,i,&info[i]);
	}
	
	gtk_entry_set_text(GTK_ENTRY(newinfo->entry_name),(const gchar *)info[0]);
	gtk_entry_set_text(GTK_ENTRY(newinfo->entry_class),!strlen(info[1])?"---":(const gchar *)info[1]);
	gtk_entry_set_text(GTK_ENTRY(newinfo->entry_tel),!strlen(info[2])?"---":(const gchar *)info[2]);
	gtk_entry_set_text(GTK_ENTRY(newinfo->entry_mail),!strlen(info[3])?"---":(const gchar *)info[3]);
	gtk_entry_set_text(GTK_ENTRY(newinfo->entry_blog),!strlen(info[4]) ?"---":(const gchar *)info[4]);
	
	g_signal_connect ((gpointer) window, "destroy",
                   G_CALLBACK (on_window_update_info_destroy),
                    NULL);
	g_signal_connect ((gpointer) newinfo->button_help, "clicked",
                    G_CALLBACK (on_button_update_info_help_clicked),
                    (gpointer)window);
	g_signal_connect ((gpointer) newinfo->button_cancel, "clicked",
                    G_CALLBACK (on_button_update_info_cancel_clicked),
                   (gpointer)window);
    
	g_signal_connect ((gpointer) newinfo->button_ok, "clicked",
                    G_CALLBACK (on_button_update_info_ok_clicked),
                    (gpointer)newinfo);
         
	return window;
}

GtkWidget*
create_window_update_group (struct addgroup_struct *addgroup,struct clist_struct *clist)
{
  	GtkWidget *window;
  	gchar *p;
  	window=(GtkWidget *)create_new_add_window(addgroup,clist);
	gtk_window_set_title (GTK_WINDOW (window), _(
					"\344\277\256\346\224\271\345\210\206\347\273\204"));
	gtk_window_set_icon_name (GTK_WINDOW (window), "gtk-refresh");
	
	gtk_clist_get_text(GTK_CLIST(clist->clist_group),clist->group_selected_row,0,&p);
	gtk_entry_set_text(GTK_ENTRY(addgroup->entry_name),(const gchar *)p);
	
	 g_signal_connect ((gpointer) window, "destroy",
                    G_CALLBACK (on_window_update_group_destroy),
                    NULL);
	g_signal_connect ((gpointer) addgroup->button_cancel, "clicked",
                    G_CALLBACK (on_button_update_group_cancel_clicked),
                    (gpointer)window);
	g_signal_connect ((gpointer) addgroup->button_ok, "clicked",
                    G_CALLBACK (on_button_update_group_ok_clicked),
                    (gpointer)addgroup);
	g_signal_connect ((gpointer) addgroup->button_help, "clicked",
                    G_CALLBACK (on_button_update_group_help_clicked),
                    (gpointer)window);
                    
	return window;
}
